'use strict'

define(['jquery', 'bootstrap', 'select2', 'shiftform', 'validate', 'validate.en', 'ajaxTab'], function($) {
  
  return {
        
    init: function() {
        this.initPage();
        this.initBrief();
        this.initLink();
    },
    
    initPage: function(){
        
        $(".ajax-tab").ajaxtab();
    },
    
    initBrief: function(){
        $(document).on("shown.bs.modal", "#brief-view", function(e) {
            var $form = $(e.currentTarget).find("form");
            
            $form.bt_validate();
            
            $form.shiftform({
                beforeSubmit: function(el) {
                        $('form').trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    },
                success: "#brief-ajax:load:refresh"
            });
        })
             
    },
    
    initLink: function(){
        $(document).on("shown.bs.modal", "#link-view", function(e) {
            var $form = $(e.currentTarget).find("form");
            
            $form.bt_validate();
            
            $form.shiftform({
                beforeSubmit: function(el) {
                        $('form').trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    },
                success: "#link-ajax:load:refresh"
            });
        })
             
    },
  }
})
